<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <link rel="stylesheet" href="../d3-tip.css" />
    <style>
     
    </style>
  </head>
  <body>


    <script src="../d3.js"></script>
    <script src="../d3-v6-tip.js"></script>
    <script>

      const width = 800 ;
      const height = 800 ;
      const svg = d3
        .select("body")
        .append("svg")
        .attr("width", width)
        .attr("height", height)
        .style("border", "1px solid #ccc");

      const g = svg.append('g').attr('transform','translate(50,50)');

      let data ;
      let root ;
      let c ;
      (async function(){
        data = await d3.json('data/china_province_city.json')   
          
        root = d3.hierarchy(data,d=>d.area);

        root.sum(d=>+d.population).sort((n1,n2)=>n1.value-n2.value)

        const pack = d3.pack()
          .size([width-100,height-100])
        
        pack(root);

        g.selectAll('circle')
          .data(root.descendants())
          .join('circle')
          .attr('cx',d=>d.x)
          .attr('cy',d=>d.y)
          .attr('r',d=>d.r)
          .attr('stroke','#ccc')
          .attr('fill',d=>d3.interpolateSinebow(d.depth/root.height/2))


        g.selectAll('text')
          .data(root.leaves())
          .join('text')
          .attr('x',d=>d.x)
          .attr('y',d=>d.y)
          .text(d=>d.data.name)
          .attr('font-size',10)
          .attr('text-anchor','middle')
          .attr('dominant-baseline','middle')
          .attr('stroke','#666')

      })();

      
      
    </script>
  </body>
</html>
